#ifndef AC_CALYPSO_TOMBALAPAGE
#define AC_CALYPSO_TOMBALAPAGE

#include "MainWindow.h"
using std::deque;

struct CodeInfo {
	int mCode;
	QString mSummary;
	QImage mImage;
	bool mAlreadyUsed;
};

namespace AirCrash {
namespace Calypso {
	
class BarcodeDecoderThread;

class CodeThread : public QThread {
	Q_OBJECT

	int mCode;

	CodeThread(const CodeThread&);

public:
	CodeThread();
	~CodeThread();

	void getCode(int code);
	void run();

signals:
	void result(QString summary, QImage image, bool alreadyUsed);
};

}
}

class TombolaPage : public QWidget {
	Q_OBJECT

	Ui::MainWindowClass * mUi;
	float mScale;
	int mLeftPos;

	QColor mBackgroundColor;
	QImage mBackgroundImage,
		mGrayBackground;
	QRect mBackArea;

	QString mInputCode;

	AirCrash::Calypso::CodeThread * mCodeThread;
	/*AirCrash::Calypso::BarcodeDecoderThread * mDecoderThread;*/

	deque<CodeInfo> mCodeInfo;
	int mCurrentItem,
		mTotalCodes;

	QFont mTextFont;
	bool mBlockInput,
		mBlocked,
		mMouseDownInCodeInput;

	QTimer mTimeTimer,
		mEmptyTimer;

	void showCurrentCodeInfo();
	void setButtonsVisibility();

protected:
	void keyPressEvent(QKeyEvent *);
	void paintEvent(QPaintEvent *);
	void showEvent(QShowEvent *);
	void hideEvent(QHideEvent *);
	void mousePressEvent(QMouseEvent * e);
	void mouseReleaseEvent(QMouseEvent * e);
	void mouseMoveEvent(QMouseEvent * e);

public:
	TombolaPage();
	~TombolaPage();

	void setUi(Ui::MainWindowClass * ui, float scale);
	void setBlocked(bool blocked);

public slots:
	void getCode();
	void databaseResult(QString summary, QImage image, bool alreadyUsed);

	void previous();
	void next();
	void deleteLast();
	void gotoNew();

	void setTime();

	void numpadInsert(const QString& number);
	void numpadDelete();
	void numpadGetCode();
};

#endif